home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
182_01
/
umodem40.c
< prev
next >
Wrap
Text File
|
1990-07-30
|
46KB
|
1,194 lines
/*
* UMODEM Version 4.0
*
* UMODEM -- Implements the "CP/M User's Group XMODEM" protocol,
* the TERM II File Transfer Protocol (FTP) Number 1,
* and the TERM II File Transfer Protocol Number 4 for
* packetized file up/downloading.
*
* Note: UNIX System-Dependent values are indicated by the string [SD]
* in a comment field on the same line as the values.
*
*
* -- Lauren Weinstein, 6/81
* -- (Version 2.0) Modified for JHU/UNIX by Richard Conn, 8/1/81
* -- Version 2.1 Mods by Richard Conn, 8/2/81
* . File Size Included on Send Option
* -- Version 2.2 Mods by Richard Conn, 8/2/81
* . Log File Generation and Option Incorporated
* -- Version 2.3 Mods by Richard Conn, 8/3/81
* . TERM II FTP 1 Supported
* . Error Log Reports Enhanced
* . CAN Function Added to FTP 3
* . 'd' Option Added to Delete umodem.log File before starting
* -- Version 2.4 Mods by Richard Conn, 8/4/81
* . 16K-extent sector number check error corrected
* . Count of number of received sectors added
* -- Version 2.5 Mods by Richard Conn, 8/5/81
* . ARPA Net Flag added
* . ARPA Net parameter ('a') added to command line
* . ARPA Net BIS, BIE, BOS, BOE added
* . ARPA Net FFH escape added
* -- Version 2.6 Mods by Bennett Marks, 8/21/81 (Bucky @ CCA-UNIX)
* . mods for UNIX V7 (Note: for JHU compilation define
* the variable JHU during 'cc'
* . added 'mungmode' flag to protect from inadvertant
* overwrite on file receive
* . changed timeout handling prior to issuing checksum
* -- Version 2.7 Mods by Richard Conn, 8/25/81 (rconn @ BRL)
* . correct minor "ifndef" error in which ifndef had no arg
* . restructured "ifdef" references so that other versions
* of UNIX than Version 7 and JHU can be easily incorporated;
* previous ifdef references were for JHU/not JHU;
* to compile under Version 7 or JHU UNIX, the following
* command lines are recommended:
* "cc umodem.c -o umodem -DVER7" for Version 7
* "cc -7 umodem.c -o umodem -DJHU" for JHU
* . added 'y' file status display option; this option gives
* the user an estimate of the size of the target file to
* send from the UNIX system in terms of CP/M records (128
* bytes) and Kbytes (1024 byte units)
* . added '7' option which modifies the transmission protocols
* for 7 significant bits rather than 8; modifies both FTP 1
* and FTP 3
* -- Version 2.8 Mods by Richard Conn, 8/28/81
* . corrected system-dependent reference to TIOCSSCR (for
* disabling page mode) and created the PAGEMODE flag which
* is to be set to TRUE to enable this
* . added -4 option which engages TERM II, FTP 4 (new release)
* -- Version 2.9 Mods by Richard Conn, 9/1/81
* . internal documentation on ARPA Net protocols expanded
* . possible operator precedence problem with BITMASK corrected
* by redundant parentheses
* -- Version 3.0 Mods by Lauren Weinstein, 9/14/81
* . fixed bug in PAGEMODE defines (removed PAGEMODE define
* line; now should be compiled with "-DPAGEMODE" if
* Page Mode is desired)
* . included forward declaration of ttyname() to avoid problems
* with newer V7 C compilers
* -- Version 3.1 Mods by Lauren Weinstein, 4/17/82
* . avoids sending extraneous last sector when file EOF
* occurs on an exact sector boundary
* -- Version 3.2 Mods by Michael M Rubenstein, 5/26/83
* . fixed bug in readbyte. assumed that int's are ordered
* from low significance to high
* . added LOGDEFAULT define to allow default logging to be
* off. compile with -DLOGDEFAULT=0 to set default to no
* logging.
* -- Version 3.3 Mod by Ben Goldfarb, 07/02/83
* . Corrected problem with above implementation of "LOGDEFAULT".
* A bitwise, instead of a logical negation operator was
* used to complement LOGFLAG when the '-l' command line
* flag was specified. This can cause LOGFLAG to be true
* when it should be false.
* -- Version 3.4 Mods by David F. Hinnant, NCECS, 7/15/83
* . placed log file in HOME directory in case user doesn't
* have write permission in working directory.
* . added DELDEFAULT define to allow default purge/no purge
* of logfile before starting. Compile with -DDELDEFAULT=0
* to set default to NOT delete the log file before starting.
* . check log file for sucessful fopen().
* . buffer disk read for sfile().
* . turn messages off (standard v7) before starting.
* -- Version 3.5 Mods by Richard Conn, 08/27/83
* . added equates for compilation under UNIX SYSTEM III
* to compile for SYSTEM III, use -DSYS3 instead of
* -DJHU or -DVER7
* . added command mode (-c option) for continuous entry
* of commands
* -- Version 4.0 Mods by Mycroft Holmes, 04/17/84
* . released constraint on using caps for commands in
* the 'command' mode.
* . added descriptors for local mode, allowing use of
* environmental variable 'MODEM' to specify
* i/o port. now, no more limitation to remote
* usage only.
* . added rudamentary terminal program for local mode
* and (ala modem7 series, thankyou
* WC) ^E exits terminal mode.
* . reassigned SIGINT to command() when in local mode, thus
* no die from program, just return to command mode.
* . put the conditional (on local mode) display of sector
* counts (so you could see it work).
* . made case conversions to lower case conditional on
* being upper case, instead of always. thus using
* lower case in commands works. (defined 'mklow')
* . put in flag to search for in order to get past all this
* garbage at the start of the file.
* . forced exit(0) on 'x' from command mode.
*EOS
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#define mklow(c) (isupper(c) ? tolower(c) : c)
#include <sgtty.h>
/* log default define */
#ifndef LOGDEFAULT
#define LOGDEFAULT 1
#endif
/* Delete logfile define. Useful on small systems with limited
* filesystem space and careless users.
*/
#ifndef DELDEFAULT
#define DELDEFAULT 1
#endif
#include <signal.h>
#define VERSION 40 /* Version Number */
#define FALSE 0
#define TRUE ~FALSE
/* Compile with "-DPAGEMODE" if Page Mode (TIOCSSCR) is supported on your
* UNIX system. If it is supported, make sure that TIOCSSCR is the
* correct name for Page Mode engagement.
*/
/* ASCII Constants */
#define SOH 001
#define STX 002
#define ETX 003
#define EOT 004
#define ENQ 005
#define ACK 006
#define LF 012 /* Unix LF/NL */
#define CR 015
#define NAK 025
#define SYN 026
#define CAN 030
#define ESC 033
#define CTRLZ 032 /* CP/M EOF for text (usually!) */
/* UMODEM Constants */
#define TIMEOUT -1
#define ERRORMAX 10 /* maximum errors tolerated */
#define RETRYMAX 10 /* maximum ret